<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-10-26 10:50:58
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-10-28 16:09:13
 * @FilePath: /httpd/wwwroot/modbus.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>自定义POST请求示例</title>
    <script>
      function sendPOSTRequest() {
        var xhr = new XMLHttpRequest(); // 创建XMLHttpRequest对象
        var url = ""; // 请求的URL，这个可以不写

        data = "data1=" + document.getElementById("data1").value + "data2=" + document.getElementById("data2").value;
        console.log("req = " + data);

        xhr.open("POST", url, true); // 配置请求：POST方法、URL、异步请求

        xhr.onreadystatechange = function() {
          if (xhr.readyState === 4 && xhr.status === 200) { // 请求完成且成功
            var response = xhr.responseText; // 获取响应数据
            console.log("resp = " + response);
            const values = response.split("");
            document.getElementById("sum1").value = values[0];
            document.getElementById("sum2").value = values[1];
            document.getElementById("sum3").value = values[2];
            document.getElementById("sum4").value = values[3];
          
          }
        };

        xhr.send(JSON.stringify(data)); // 发送请求，并将数据转换为JSON字符串
      }
    </script>
  </head>
  <body>
    LED设置: <input type="text" id="data1" value="1"><br />
    BEEP设置: <input type="text" id="data2" value="2"><br />
    坐标: <input type="text" id="sum1" placeholder="这里显示和"><br />
    x: <input type="text" id="sum2" placeholder="这里显示和"><br />
    y: <input type="text" id="sum3" placeholder="这里显示和"><br />
    z: <input type="text" id="sum4" placeholder="这里显示和"><br />
    <br />
    <button onclick="sendPOSTRequest()">确定</button>
  </body>
</html>
